/*
 * Project Name JPEG API for HW JPEG IP IN WINCE
 * Copyright  2007 Samsung Electronics Co, Ltd. All Rights Reserved. 
 *
 * This software is the confidential and proprietary information
 * of Samsung Electronics  ("Confidential Information").   
 * you shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Samsung Electronics 
 *
 * This file implements JPEG driver.
 *
 * @name JPEG DRIVER MODULE Module (JPGApi.h)
 * @author Jiyoung Shin (idon.shin@samsung.com)
 * @date 28-05-07
 */
#define JPG_DRIVER_NAME		L"JPG1:"


#define CTL_CODE( DeviceType, Function, Method, Access ) (                 \
	((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
	)

#define IOCTL_JPG_DECODE			CTL_CODE( 0, 0x810, 0, 0 )
#define IOCTL_JPG_ENCODE			CTL_CODE( 0, 0x811, 0, 0 )
#define IOCTL_JPG_GET_STRBUF		CTL_CODE( 0, 0x812, 0, 0 )
#define IOCTL_JPG_GET_FRMBUF		CTL_CODE( 0, 0x813, 0, 0 )
#define IOCTL_JPG_GET_PHY_FRMBUF	CTL_CODE( 0, 0x814, 0, 0 )
#define IOCTL_JPG_GET_THUMB_STRBUF	CTL_CODE( 0, 0x815, 0, 0 )
#define IOCTL_JPG_GET_THUMB_FRMBUF	CTL_CODE( 0, 0x816, 0, 0 )
#define IOCTL_JPG_GET_RGBBUF			CTL_CODE( 0, 0x817, 0, 0 )
#define IOCTL_JPG_GET_PHY_RGBBUF		CTL_CODE( 0, 0x818, 0, 0 )
#define IOCTL_JPG_GET_PHY_RGBBUF_ROTATE  CTL_CODE( 0, 0x819, 0, 0 )
#define IOCTL_JPG_GET_RGBBUF_ROTATE CTL_CODE( 0, 0x820, 0, 0 )


#define MAX_JPG_WIDTH				2592
#define MAX_JPG_HEIGHT				2048
#define MAX_YUV_SIZE				(MAX_JPG_WIDTH * MAX_JPG_HEIGHT * 2)
#define	MAX_FILE_SIZE				(MAX_JPG_WIDTH * MAX_JPG_HEIGHT)
#define MAX_JPG_THUMBNAIL_WIDTH		160
#define MAX_JPG_THUMBNAIL_HEIGHT	120
#define MAX_YUV_THUMB_SIZE			(MAX_JPG_THUMBNAIL_WIDTH * MAX_JPG_THUMBNAIL_HEIGHT * 2)
#define	MAX_FILE_THUMB_SIZE			(MAX_JPG_THUMBNAIL_WIDTH * MAX_JPG_THUMBNAIL_HEIGHT)
#define MAX_RGB_WIDTH				800
#define MAX_RGB_HEIGHT				480
#define EXIF_FILE_SIZE				28800


typedef enum tagSAMPLE_MODE_T{
	JPG_444,
	JPG_422,
	JPG_420, 
	JPG_411,
	JPG_400,
	JPG_SAMPLE_UNKNOWN
}SAMPLE_MODE_T;

typedef enum tagIMAGE_QUALITY_TYPE_T{
	JPG_QUALITY_LEVEL_1 = 0, /*high quality*/
	JPG_QUALITY_LEVEL_2,
	JPG_QUALITY_LEVEL_3,
	JPG_QUALITY_LEVEL_4     /*low quality*/
}IMAGE_QUALITY_TYPE_T;

typedef enum tagJPEGConf{
	JPEG_GET_DECODE_WIDTH,
	JPEG_GET_DECODE_HEIGHT,
	JPEG_GET_SAMPING_MODE,
	JPEG_SET_ENCODE_WIDTH,
	JPEG_SET_ENCODE_HEIGHT,
	JPEG_SET_ENCODE_QUALITY,
	JPEG_SET_ENCODE_THUMBNAIL,
	JPEG_SET_SAMPING_MODE,
	JPEG_SET_THUMBNAIL_WIDTH,
	JPEG_SET_THUMBNAIL_HEIGHT
}JPEGConf;

typedef enum tagJPEG_ERRORTYPE{
	JPEG_FAIL,
	JPEG_OK,
	JPEG_ENCODE_FAIL,
	JPEG_ENCODE_OK,
	JPEG_DECODE_FAIL,
	JPEG_DECODE_OK,
	JPEG_HEADER_PARSE_FAIL,
	JPEG_HEADER_PARSE_OK,
	JPEG_DISPLAY_FAIL,
	JPEG_UNKNOWN_ERROR
}JPEG_ERRORTYPE;

typedef struct tagExifFileInfo{
	char	Make[32]; 
	char	Model[32]; 
	char	Version[32]; 
	char	DateTime[32]; 
	char	CopyRight[32]; 

	UINT	Height; 
	UINT	Width;
	UINT	Orientation; 
	UINT	ColorSpace; 
	UINT	Process;
	UINT	Flash; 

	UINT	FocalLengthNum; 
	UINT	FocalLengthDen; 

	UINT	ExposureTimeNum; 
	UINT	ExposureTimeDen; 

	UINT	FNumberNum; 
	UINT	FNumberDen; 

	UINT	ApertureFNumber; 

	int		SubjectDistanceNum; 
	int		SubjectDistanceDen; 

	UINT	CCDWidth;

	int		ExposureBiasNum; 
	int		ExposureBiasDen; 


	int		WhiteBalance; 

	UINT	MeteringMode; 

	int		ExposureProgram;

	UINT	ISOSpeedRatings[2]; 

	UINT	FocalPlaneXResolutionNum;
	UINT	FocalPlaneXResolutionDen;

	UINT	FocalPlaneYResolutionNum;
	UINT	FocalPlaneYResolutionDen;

	UINT	FocalPlaneResolutionUnit;

	UINT	XResolutionNum;
	UINT	XResolutionDen;
	UINT	YResolutionNum;
	UINT	YResolutionDen;
	UINT	RUnit; 

	int		BrightnessNum; 
	int		BrightnessDen; 

	char	UserComments[150];
}ExifFileInfo;


#define TRUE	1
#define FALSE	0

//#define DEBUG   0

//////////////////////////////////////////////////////////////////////////////////////
// Type Define																		//
//////////////////////////////////////////////////////////////////////////////////////
typedef enum tagENCDEC_TYPE_T{
	JPG_MAIN,
	JPG_THUMBNAIL
}ENCDEC_TYPE_T;

typedef struct tagJPG_DEC_PROC_PARAM{
	SAMPLE_MODE_T	sampleMode;
	ENCDEC_TYPE_T	decType;
	UINT32	width;
	UINT32	height;
	UINT32	dataSize;
	UINT32	fileSize;
} JPG_DEC_PROC_PARAM;

typedef struct tagJPG_ENC_PROC_PARAM{
	SAMPLE_MODE_T	sampleMode;
	ENCDEC_TYPE_T	encType;
	IMAGE_QUALITY_TYPE_T quality;
	UINT32	width;
	UINT32	height;
	UINT32	dataSize;
	UINT32	fileSize;
} JPG_ENC_PROC_PARAM;

typedef struct tagJPG_CTX{
	UINT	debugPrint;
	char	*InBuf;
	char	*OutBuf;
	char	*InThumbBuf;
	char	*OutThumbBuf;
	UINT8	thumbnailFlag;
	JPG_DEC_PROC_PARAM	*decParam;
	JPG_ENC_PROC_PARAM	*encParam;
	JPG_ENC_PROC_PARAM	*thumbEncParam;
	ExifFileInfo *ExifInfo;
}JPG_CTX;




